package com.fumin.service.impl;

import com.fumin.mapper.InvestmentRecordMapper;
import com.fumin.mapper.ProjectsMapper;
import com.fumin.pojo.InvestmentRecord;
import com.fumin.pojo.Projects;
import com.fumin.service.ProjectsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by Lingo on 2018/3/4.
 */
@Service
public class ProjectsServiceImpl implements ProjectsService {


    @Resource
    ProjectsMapper projectsMapper;
    @Resource
    InvestmentRecordMapper investmentRecordMapper;



    @Override
    public int deleteByPrimaryKey(Long pk) {
        return projectsMapper.deleteByPrimaryKey(pk);
    }

    @Override
    public int insert(Projects record) {
        return projectsMapper.insert(record);
    }

    @Override
    public int insertSelective(Projects record) {
        return projectsMapper.insertSelective(record);
    }

    @Override
    public Projects selectByPrimaryKey(Long pk) {
        return projectsMapper.selectByPrimaryKey(pk);
    }

    @Override
    public int updateByPrimaryKeySelective(Projects record) {
        return projectsMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKeyWithBLOBs(Projects record) {
        return projectsMapper.updateByPrimaryKeyWithBLOBs(record);
    }

    @Override
    public int updateByPrimaryKey(Projects record) {
        return projectsMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Projects> selectPage(Integer start, Integer offset) {
        return projectsMapper.selectPage(start,offset);
    }

    @Override
    public List<Projects> selectPageByStatus(Integer start, Integer offset, Integer status) {
        return projectsMapper.selectPageByStatus(start,offset,status);
    }

    @Override
    public Map<String, Long> selectNumByStatus(Integer status) {
        return projectsMapper.selectNumByStatus(status);
    }

    @Override
    public Float checkTheAmountOfProject(Long projectPk) {
        InvestmentRecord investmentRecord =investmentRecordMapper.selectByProjectPk(projectPk);
        if (investmentRecord==null){
            return 0F;
        }
        return investmentRecord.getAmount();
    }

    @Override
    public List<Projects> selectPageByName(Integer start, Integer offset, String name) {
        return projectsMapper.selectPageByName(start,offset,name);
    }
}
